package com.lenovo.lcdm.type.controller;

import com.lenovo.lcdm.common.model.ResponseVo;
import com.lenovo.lcdm.type.dto.DataTypeDTO;
import com.lenovo.lcdm.type.dto.GlobalAttributeDTO;
import com.lenovo.lcdm.type.entity.TypeGlobalAttribute;
import com.lenovo.lcdm.type.service.TypeGlobalAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc GlobalAttribute对象管理微服务对外接口
 *
 * @author xujing30
 * @date 2024-01-11
 */
@RestController
public class GlobalAttributeController {


    @Autowired
    private TypeGlobalAttributeService globalAttributeService;

    @GetMapping("/{attributeFolderId}/global-attribute")
    public ResponseVo<List<GlobalAttributeDTO>> queryGlobalAttribute(@PathVariable("attributeFolderId") Long attributeFolderId) {
        ResponseVo<List<GlobalAttributeDTO>> responseVo = new ResponseVo<>();
        List<GlobalAttributeDTO> data = globalAttributeService.queryGlobalAttribute(attributeFolderId);
        responseVo.setData(data);
        return responseVo;
    }

    @PostMapping("/global-attribute")
    public ResponseVo<GlobalAttributeDTO> createGlobalAttribute(@RequestBody GlobalAttributeDTO globalAttributeDTO) {
        ResponseVo<GlobalAttributeDTO> responseVo = new ResponseVo<>();
        GlobalAttributeDTO data = globalAttributeService.createGlobalAttribute(globalAttributeDTO);
        responseVo.setData(data);
        return responseVo;
    }

    @PutMapping("/global-attribute")
    public ResponseVo<Object> updateGlobalAttribute(@RequestBody GlobalAttributeDTO globalAttributeDTO) {
        ResponseVo<Object> responseVo = new ResponseVo<>();
        globalAttributeService.updateGlobalAttribute(globalAttributeDTO);
        return responseVo;
    }


    @DeleteMapping("/global-attribute")
    public ResponseVo<Object> deleteGlobalAttribute(@RequestBody GlobalAttributeDTO globalAttributeDTO) {
        ResponseVo<Object> responseVo = new ResponseVo<>();
        globalAttributeService.deleteGlobalAttribute(globalAttributeDTO);
        return responseVo;
    }

    @GetMapping("/global-attribute/{id}")
    public ResponseVo<TypeGlobalAttribute> getGlobalAttribute(@PathVariable("id") Long id) {
        ResponseVo<TypeGlobalAttribute> ResponseVo = new ResponseVo<>();
        TypeGlobalAttribute globalAttribute = globalAttributeService.getById(id);
        ResponseVo.setData(globalAttribute);
        return ResponseVo;
    }

    @GetMapping("/data-type")
    public ResponseVo<List<DataTypeDTO>> queryDataTypes() {
        ResponseVo<List<DataTypeDTO>> responseVo = new ResponseVo<>();
        List<DataTypeDTO> data = globalAttributeService.queryDataType();
        responseVo.setData(data);
        return responseVo;
    }

}
